package com.yycx.module.bus.provider.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.yycx.common.mybatis.model.*;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.module.bus.client.entity.BusSfinance;
import com.yycx.module.bus.provider.service.BusSfinanceService;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 厂家对账表控制器
 *
 * @author flyme
 * @date 2021-02-19
 */
@RestController
@RequestMapping("/bus/sfinance/")
public class BusSfinanceController extends BaseController<BusSfinanceService, BusSfinance>  {

    @ApiOperation(value = "厂家对账表-分页列表", notes = "厂家对账表分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "厂家对账表-列表", notes = "厂家对账表列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "厂家对账表-添加", notes = "添加厂家对账表")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "厂家对账表-更新", notes = "更新厂家对账表")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "厂家对账表-删除", notes = "删除厂家对账表")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "厂家对账表-详情", notes = "厂家对账表详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @ApiOperation(value = "厂家对账表-导入数据", notes = "厂家对账表-导入数据")
    @PostMapping(value = "importData")
    public ResultBody importData(@RequestParam(required = false) Map params, @RequestParam("file") MultipartFile file) {
        ResultBody resultBody = bizService.importData(file, params);
        return resultBody;
    }

    @ApiOperation(value = "厂家对账表-导出数据", notes = "厂家对账表-导出数据")
    @PostMapping(value = "exportData")
    public void exportData(HttpServletRequest request, HttpServletResponse response, @RequestParam Long sfinanceId) {
        bizService.exportData(response, sfinanceId);
    }


    @ApiOperation(value = "厂家对账表-初始化数据", notes = "厂家对账表-初始化数据")
    @PostMapping(value = "syncData")
    public ResultBody syncData(@RequestParam Long sfinanceId) {
        Thread t = new Thread(() -> {
            bizService.initData(sfinanceId);
        });
        t.start();
        return ResultBody.ok();
    }

}
